public class ClaimExtensionVF
{
    private Claim__c[] claim = new Claim__c[1];
    private ID oppId = null;
    public List<Opportunity> opportunityList {get; set;}
    public Integer expectedCredit {get; set;}   
    public Integer ytdAttainment {get; set;}    
    public Integer commisionRate {get; set;}    
    public Integer commissionAmount {get; set;} 
    public String comments {get; set;}  
    public Boolean approveButFlag {get; set;}
    public Boolean rejectButFlag {get; set;}
    public Boolean adjustAndApproveButFlag {get; set;}
    public Boolean sendInquiryButFlag {get; set;}
    public Boolean calculateButFlag {get; set;}
    public Boolean fileClaimButFlag {get; set;}
    public Boolean lookupPlanManagerButFlag {get; set;}
    public Boolean lookupPlanButFlag {get; set;}
    public Boolean claimedUserFlag {get; set;}
    public Boolean managerFlag {get; set;}
    
        
    public ClaimExtensionVF(ApexPages.StandardController myController)
    {
        claim[0] = (Claim__c)myController.getRecord();
        oppId = [select Opportunity__c from Claim__c where id = : claim[0].id].Opportunity__c;
//        OppClaimImpl oci = new OppClaimImpl();
          //getOpportunityDetails();
        Claim__c[] c = [select OwnerId, Claim__c.CreatedBy.ID from Claim__c where id = :claim[0].id];
        if(c[0].CreatedBy.Id == UserInfo.getUserId())
        {
        	calculateButFlag = fileClaimButFlag = lookupPlanButFlag = claimedUserFlag = true;
            approveButFlag = adjustAndApproveButFlag = sendInquiryButFlag = lookupPlanManagerButFlag = rejectButFlag = managerFlag = false;
        }
        else
        {
        	calculateButFlag = fileClaimButFlag = lookupPlanButFlag = claimedUserFlag = false;
            approveButFlag = adjustAndApproveButFlag = sendInquiryButFlag = lookupPlanManagerButFlag = rejectButFlag = managerFlag = true;
        }
    }
    
    public List<Opportunity> getOpportunityDetails()
    {
        opportunityList = [select Name, Amount, AccountId, Opportunity.Account.Name, ExpectedRevenue, Type, Description, OwnerId, Opportunity.Owner.Name, CloseDate, LeadSource, Opportunity.Campaign.Name, MainCompetitors__c, OrderNumber__c, CurrentGenerators__c, TrackingNumber__c from Opportunity where id = :oppId];
        return opportunityList;
    }
    
    public PageReference calculate()
    {
        return null;
    }

    public PageReference lookupPlanDocument()
    {
        return null;
    }

    public PageReference fileClaim()
    {
        return null;
    }

    public PageReference approve()
    {
    	try
    	{
			ProcessInstance[] prInst = [Select Id from ProcessInstance where TargetObjectId=:claim[0].Id and Status='Pending'];
			if(prInst.size()>0)		
			{
	
	            ProcessInstanceWorkitem[] prInstWItem = [select Id,OriginalActorId from ProcessInstanceWorkitem where ProcessInstanceId = :prInst[0].Id]; 
	
	            Approval.ProcessWorkitemRequest prWkItem = new Approval.ProcessWorkitemRequest();
	
				prWkItem.setWorkitemId(prInstWItem[0].Id);
	
				prWkItem.setComments('Approved'); 
				
				prWkItem.setAction('Approve'); 
				
				Approval.ProcessResult prResult = Approval.process(prWkItem);
			}
    	}
    	catch(Exception e)
    	{
    		ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info, e.getMessage()));
    	}
        return null;
    }

    public PageReference adjustAndApprove()
    {
        return null;
    }

    public PageReference reject()
    {
        return null;
    }
    
    public PageReference sendInquiry()
    {
        return null;
    }
    
    public Claim__c getClaimData()
    {
        Claim__c[] claimData = [select id, Name, Claim__c.Opportunity__r.Amount, Commission_Amount__c, Claim_Status__c, Commission_Rate__c, Attainment__c, Credit__c, Comments__c, Adjusted_Credit__c, Adjusted_Commission__c from Claim__c where id = :claim[0].id];
        if(claimData.size() > 0)
            return claimData[0];
        return null;
    }
}